//
//  XSLoginViewController.m
//  MeiLiYiChu
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "XSLoginViewController.h"

#import "XSRegistViewController.h"
@interface XSLoginViewController ()
{
    UITextField  *userTF;
    UITextField  *pass;
}
@end

@implementation XSLoginViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden =YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor =[UIColor whiteColor];
    
    XSView * view =[[XSView alloc]initWithBool:NO withString:@"登录"];
    [self.view addSubview:view];
    UIButton * btn1 =(UIButton *)[view viewWithTag:1];
    [btn1 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIView * userView =[[UIView alloc]init];
    
    userView.backgroundColor =[UIColor grayColor];
    [self.view addSubview:userView];
    [userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(104);
        make.left.offset(10);
        make.right.offset(-10);
        make.height.equalTo(@50);
        
        
    }];
    
    userTF =[[UITextField alloc]init];
    userTF.placeholder =@"手机号";
    userTF.backgroundColor =[UIColor lightTextColor];
    [userView addSubview:userTF];
    [userTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(50);
        make.right.offset(0);
        make.bottom.offset(0);
    }];
    
    UIImageView * imageView =[[UIImageView alloc]init];
    imageView.image =[UIImage imageNamed:@"login_user_icon"];
    imageView.frame =CGRectMake(0, 0, 50, 50);
    imageView.backgroundColor =[UIColor grayColor];
    [userView addSubview:imageView];
    
    
    UIView * passView =[[UIView alloc]init];
    
    passView.backgroundColor =[UIColor grayColor];
    [self.view addSubview:passView];
    [passView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(userView.mas_bottom).with.offset(20);
        make.left.offset(10);
        make.right.offset(-10);
        make.height.equalTo(@50);
    }];
    
    pass =[[UITextField alloc]init];
    pass.placeholder =@"密码";
    pass.backgroundColor =[UIColor lightTextColor];
    [passView addSubview:pass];
    
    [pass mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(50);
        make.right.offset(0);
        make.bottom.offset(0);
    }];
    
    UIImageView * imageView1 =[[UIImageView alloc]init];
    imageView1.image =[UIImage imageNamed:@"login_pass_icon"];
    imageView1.frame =CGRectMake(0, 0, 50, 50);
    [passView addSubview:imageView1];

    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.center =CGPointMake(self.view.center.x, self.view.center.y+15);
    button.bounds =CGRectMake(0, 0, 250, 40);
    

    [button setTitle:@"登录" forState:UIControlStateNormal];
    button.backgroundColor =[UIColor magentaColor];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button1.center =CGPointMake(self.view.center.x, button.frame.origin.y+40 +50);
    button1.bounds =CGRectMake(0, 0, 250, 40);
    
    
    [button1 setTitle:@"注册" forState:UIControlStateNormal];
    button1.backgroundColor =[UIColor whiteColor];
    [button1 setTitleColor:[UIColor magentaColor] forState:UIControlStateNormal];
    
    [button1 addTarget:self action:@selector(registBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    button1.layer.borderColor =[UIColor magentaColor].CGColor;
    button1.layer.borderWidth =2;
    
    UIView * bottomView =[[UIView alloc]init];
    
    bottomView.backgroundColor =backColor;
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(0);
        make.height.equalTo(@130);
    }];
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];

    button2.center =CGPointMake(self.view.center.x, bottomView.center.y+60);
    button2.bounds =CGRectMake(0, 0, 80, 100);
    
    [button2 addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:button2];

    
    UIImageView * image =[[UIImageView alloc]init];
    image.center =CGPointMake(button2.center.x, button2.center.y);
    image.bounds =CGRectMake(0, 0, 50, 50);
    image.image =[UIImage imageNamed:@"yuike_share_weixin_friend_un"];
    [bottomView addSubview:image];
    
    UILabel * lab =[[UILabel alloc]init];
    lab.center =CGPointMake(image.center.x, image.center.y+40);
    lab.bounds =CGRectMake(0, 0, 80, 20);
    lab.textAlignment =NSTextAlignmentCenter;
    lab.text =@"微信登录";
    [bottomView addSubview:lab];
    lab.userInteractionEnabled =NO;
    image.userInteractionEnabled =NO;
}
-(void)loginClick
{
    NSLog(@"6546465");
}
-(void)back
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)login
{
    [XSHTTPManager getLoginPlistWithComplection:^(NSMutableArray *array) {
        
        _block(array);
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    } withUserID:userTF.text Withpsw:pass.text];
    
    
    
}
-(void)registBtn
{
    XSRegistViewController * regisetVC =[[XSRegistViewController alloc]init];
    self.hidesBottomBarWhenPushed =YES;
    [self.navigationController pushViewController:regisetVC animated:YES];
    self.hidesBottomBarWhenPushed =NO;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
